//
//  PMinePromotionCell.m
//  Btpin
//
//  Created by Vic on 2019/9/25.
//  Copyright © 2019 Vic. All rights reserved.
//

#import "PMinePromotionCell.h"

@interface PMinePromotionCell ()
{
    UILabel *titleLbl;
    UILabel *baseInfoLbl;
    UILabel *companyNameLbl;
    UIImageView *integrityTagImgView;
    UILabel *companyInfoLbl;
    UIImageView *headerImgView;
    UILabel *wageLbl;
    UILabel *rewardLbl;
}
@end

@implementation PMinePromotionCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initUI];
    }
    return self;
}
- (void)initUI {
    titleLbl = [UIToolsControl initLabelWithFrame:CGRectMake(LeftSpace, 15*Scale, WIDTH-100*Scale, 30*Scale) text:nil textColor:THEMECOLOR_OF_TEXT_333333 font:Font_18];
    titleLbl.font = FontBold(Font_18);
    [self.contentView addSubview:titleLbl];
    
    wageLbl = [UIToolsControl initLabelWithFrame:CGRectMake(EndX(titleLbl)+ScalePS(10), 25*Scale, 200, 17*Scale) text:nil textColor:THEMECOLOR_OF_RED font:Font_15];
    [self.contentView addSubview:wageLbl];
    
    baseInfoLbl = [UIToolsControl initLabelWithFrame:CGRectMake(StartX(titleLbl), EndY(titleLbl), ViewWidth(titleLbl), 25*Scale) text:nil textColor:THEMECOLOR_OF_TEXT_666666 font:Font_13];
    [self.contentView addSubview:baseInfoLbl];
    
    headerImgView = [UIToolsControl initImageViewWithFrame:CGRectMake(StartX(titleLbl), EndY(baseInfoLbl)+10*Scale, 40*Scale, 40*Scale) imageName:@"header_bg"];
    headerImgView.contentMode = UIViewContentModeScaleAspectFill;
    headerImgView.layer.cornerRadius = 20*Scale;
    headerImgView.layer.masksToBounds = YES;
    [self.contentView addSubview:headerImgView];
    
    companyNameLbl = [UIToolsControl initLabelWithFrame:CGRectMake(EndX(headerImgView)+10*Scale, StartY(headerImgView), 100, 25*Scale) text:nil textColor:THEMECOLOR_OF_TEXT_333333 font:Font_15];
    [self.contentView addSubview:companyNameLbl];
    
    integrityTagImgView = [UIToolsControl initImageViewWithFrame:CGRectMake(EndX(companyNameLbl)+2, StartY(companyNameLbl)+3*Scale, 14*Scale, 14*Scale) imageName:@"integrity_tag"];
    integrityTagImgView.hidden = YES;
    [self.contentView addSubview:integrityTagImgView];
    
    companyInfoLbl = [UIToolsControl initLabelWithFrame:CGRectMake(StartX(companyNameLbl), EndY(companyNameLbl), WIDTH-80*Scale, 15*Scale) text:nil textColor:THEMECOLOR_OF_TEXT_333333 font:Font_13];
    [self.contentView addSubview:companyInfoLbl];
    
    rewardLbl = [UIToolsControl initLabelWithFrame:CGRectMake(WIDTH-ScalePS(70), ScalePS(20), ScalePS(52), ScalePS(52)) text:nil textColor:THEMECOLOR_OF_RED font:Font_12];
    rewardLbl.numberOfLines = 0;
    rewardLbl.lineBreakMode = NSLineBreakByWordWrapping;
    rewardLbl.layer.borderColor = THEMECOLOR_OF_RED.CGColor;
    rewardLbl.layer.borderWidth = 1;
    rewardLbl.layer.cornerRadius = ScalePS(26);
    rewardLbl.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:rewardLbl];
    rewardLbl.hidden = YES;
    
    UIView *lineView = [UIToolsControl initViewWithFrame:CGRectMake(0, EndY(headerImgView)+18*Scale, WIDTH, 8*Scale) backgroundColor:THEMECOLOR_OF_GRAY];
    [self.contentView addSubview:lineView];
}
- (void)reloadData {
    NSString *titleStr = @"资深程序架构师—App";
    CGFloat titleWidth = [UIToolsControl textWidth:titleStr size:CGSizeMake(MAXFLOAT, ScalePS(30)) font:Font_18]+1;
    titleLbl.frame = CGRectMake(LeftSpace, 15*Scale, titleWidth, 30*Scale);
    wageLbl.frame = CGRectMake(EndX(titleLbl)+ScalePS(10), 23*Scale, 200, 17*Scale);
    titleLbl.text = @"资深程序架构师—App";
    baseInfoLbl.text = [NSString stringWithFormat:@"%@ | %@ | %@ | %@", @"北京", @"通州", @"3-5年", @"本科"];
    
    NSString *companyName = @"同心互联";
    companyNameLbl.text = companyName;
    companyInfoLbl.text = [NSString stringWithFormat:@"%@ | %@ | %@", @"天使轮", @"50-100人", @"移动互联网"];
    wageLbl.text = @"25K-35K";
    rewardLbl.text = @"赚\n30聘豆";
    rewardLbl.hidden = NO;
    
    CGFloat width = [UIToolsControl textWidth:companyName size:CGSizeMake(MAXFLOAT, 25*Scale) font:Font_18]+1;
    companyNameLbl.frame = CGRectMake(EndX(headerImgView)+10*Scale, StartY(headerImgView), width, 20*Scale);
    integrityTagImgView.frame = CGRectMake(EndX(companyNameLbl)+2, StartY(companyNameLbl)+3*Scale, 14*Scale, 14*Scale);
}
- (void)reloadDataForPromotionModel:(CompanyJobModel *)model {
    CGFloat titleWidth = [UIToolsControl textWidth:model.title size:CGSizeMake(MAXFLOAT, ScalePS(30)) font:Font_18]+1;
    titleLbl.frame = CGRectMake(LeftSpace, 15*Scale, titleWidth, 30*Scale);
    wageLbl.frame = CGRectMake(EndX(titleLbl)+ScalePS(10), 23*Scale, 200, 17*Scale);
    titleLbl.text = model.title;
    baseInfoLbl.text = [NSString stringWithFormat:@"%@ | %@ | %@", model.district_cn, model.experience_cn, model.education_cn];
    
    NSString *companyName = model.company_name;
    companyNameLbl.text = companyName;
    companyInfoLbl.text = [NSString stringWithFormat:@"%@ | %@ | %@", model.finance_cn, model.scale_cn, model.trade_cn];
    if (model.company_logo && model.company_logo.length) {
        [headerImgView sd_setImageWithURL:[NSURL URLWithString:model.company_logo] placeholderImage:[UIImage imageNamed:@"header_bg"]];
    } else {
        headerImgView.image = [UIImage imageNamed:@"header_bg"];
    }
    wageLbl.text = model.wage_cn;
    if ([model.promote_status integerValue] == 1) {
        rewardLbl.hidden = NO;
        rewardLbl.text = [NSString stringWithFormat:@"赚\n%@聘豆", model.promote_price];
    } else {
        rewardLbl.hidden = YES;
    }
    
    CGFloat width = [UIToolsControl textWidth:companyName size:CGSizeMake(MAXFLOAT, 20*Scale) font:Font_15]+1;
    companyNameLbl.frame = CGRectMake(EndX(headerImgView)+10*Scale, StartY(headerImgView), MIN(width, WIDTH-100*Scale), 20*Scale);
    integrityTagImgView.frame = CGRectMake(EndX(companyNameLbl)+2, StartY(companyNameLbl)+3*Scale, 14*Scale, 14*Scale);
    if (model.company_auth_medal && model.company_auth_medal.length && [model.company_auth_medal isEqualToString:@"1"]) {
        integrityTagImgView.hidden = NO;
    } else {
        integrityTagImgView.hidden = YES;
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}

@end
